package DataFile;

import java.nio.ByteBuffer;
import java.util.Formatter;

import ClassData.ConstantPoolDouble_Info;


public class Structure_CP_DoubleInfo extends Structure_CP_Constant {

	ConstantPoolDouble_Info myDoubleInfo;
	
	public Structure_CP_DoubleInfo(ConstantPoolDouble_Info myDoubleInfo) {
		this.myDoubleInfo=myDoubleInfo;
	}

	public int getMemorySize() {
		int size;
		
		size=BYTE_WIDTH;	// Type
		size+=DOUBLE_WIDTH;	// class name index
		
		return(size);
	}

	protected String getMemoryMapAsString() {
		String returnString;
		
		returnString=getAdressAsHexString(baseAdress);
		returnString+=" : (double info) : size - "+new Formatter().format("%3d",getMemorySize());
		returnString+=" Value : "+myDoubleInfo.getValue()+"\n";
		
		return(returnString);
	}
	
	/**
	 *  writes data into memory file
	 *  
	 *  @author Tavin
	 *  
	 *  @param fileData buffer for data 
	 */
	
	public void writeData(ByteBuffer fileData) {
		fileData.position(baseAdress-DataFileCreator.BASE_MEMORY_ADRESS);
		fileData.put((byte)myDoubleInfo.getType());
		fileData.putDouble(myDoubleInfo.getValue());
	}
}
